home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / tcp / HyperMail102.lha / HyperMail / file.c < prev    next >
C/C++ Source or Header  |  1995-06-18  |  5KB  |  227 lines

  1. /*
  2. ** Copyright (C) 1994, Enterprise Integration Technologies Corp.        
  3. ** All Rights Reserved.
  4. ** Kevin Hughes, kevinh@eit.com 
  5. ** 7/25/94
  6. */
  7.  
  8. #include "hypermail.h"
  9. #include "file.h"
  10.  
  11. #if defined (AMIGA) && !defined(__GNUC__)
  12. #include <proto/dos.h>
  13. #include <proto/exec.h>
  14. #include <exec/memory.h>
  15.  
  16. /* Is a file a directory? The Amiga way of doing things
  17. */
  18.  
  19. int isdirectory(char *path)
  20. {
  21.     BPTR lock=NULL;
  22.     BOOL gotit=FALSE;
  23.     struct FileInfoBlock *fib=NULL;
  24.  
  25.     fib=AllocVec(sizeof(struct FileInfoBlock),MEMF_PUBLIC | MEMF_CLEAR);
  26.     if(!fib) return(0);
  27.     lock=Lock(path,ACCESS_READ);
  28.     if(!lock)
  29.     {
  30.         FreeVec(fib);
  31.         return(0);
  32.     }
  33.     gotit=Examine(lock,fib);
  34.     if(gotit)
  35.     {
  36.         if(fib->fib_DirEntryType>0)
  37.             gotit=TRUE;
  38.         if(fib->fib_DirEntryType<0)
  39.             gotit=FALSE;
  40.     }
  41.     UnLock(lock);
  42.     FreeVec(fib);
  43.     return(gotit);
  44. }
  45.  
  46.  
  47. /* Is a file a file? Tested the Amiga way
  48. */
  49.  
  50. int isfile(char *path)
  51. {
  52.     BPTR lock=NULL;
  53.     BOOL gotit=FALSE;
  54.     struct FileInfoBlock *fib=NULL;
  55.  
  56.     fib=AllocVec(sizeof(struct FileInfoBlock),MEMF_PUBLIC | MEMF_CLEAR);
  57.     if(!fib) return(0);
  58.     lock=Lock(path,ACCESS_READ);
  59.     if(!lock)
  60.     {
  61.         FreeVec(fib);
  62.         return(0);
  63.     }
  64.     gotit=Examine(lock,fib);
  65.     if(gotit)
  66.     {
  67.         if(fib->fib_DirEntryType>0)
  68.             gotit=FALSE;
  69.         if(fib->fib_DirEntryType<0)
  70.             gotit=TRUE;
  71.     }
  72.     UnLock(lock);
  73.     FreeVec(fib);
  74.     return(gotit);
  75. }
  76.  
  77. /* don't have a chmod function, could make one out of SetProtection() though */
  78. chmod()
  79. {
  80.     return(0);
  81. }
  82.  
  83. /*
  84. __swbuf(){}
  85. __sF(){}
  86. getpwuid(){}
  87. getuid(){}
  88. */
  89. #else
  90.  
  91. /* Is a file a directory?
  92. */
  93.  
  94. int isdirectory(path)
  95.      char *path;
  96. {
  97.     struct stat stbuf;
  98.  
  99.     if (stat(path, &stbuf))
  100.         return 0;
  101. /*    return ((stbuf.st_mode & S_IFMT) == S_IFDIR) ? 1 : 0;*/
  102.     return(1);
  103.  
  104. }
  105.  
  106. /* Does a file exist?
  107. */
  108.  
  109. int isfile(path)
  110.      char *path;
  111. {
  112.  
  113.     struct stat stbuf;
  114.  
  115.     if (stat(path, &stbuf))
  116.         return 0;
  117.     return ((stbuf.st_mode & S_IFMT) == S_IFREG) ? 1 : 0;
  118.     return(1);
  119. }
  120. #endif
  121.  
  122. /* This tries to create and chmod a directory.
  123. */
  124.  
  125. void checkdir(dir)
  126.      char *dir;
  127. {
  128.  
  129.     if (!isdirectory(dir)) {
  130.         if (mkdir(dir, dirmode) == -1) {
  131.             sprintf(errmsg,
  132.             "Couldn't create archive directory \"%s\".", dir);
  133.             progerr(NULL);
  134.         }
  135.         else if (showprogress)
  136.             printf("Creating directory \"%s\", mode %o.\n",
  137.             dir, dirmode);
  138.         if (chmod(dir, dirmode) == -1) {
  139.             sprintf(errmsg, "Couldn't chmod \"%s\" to %o.",
  140.             dir, dirmode);
  141.             progerr(NULL);
  142.         }
  143.     }
  144.  
  145. }
  146.  
  147. /* Reads a configuration file if it exists and puts all the right
  148. ** values into the right variables.
  149. */
  150.  
  151. void readconfigs(path, mbox, label, dir, archives, about, overwrite, increment,
  152. defaultindex)
  153.      char *path;
  154.      char *mbox;
  155.      char *label;
  156.      char *dir;
  157.      char *archives;
  158.      char *about;
  159.      int *overwrite;
  160.      int *increment;
  161.      char *defaultindex;
  162. {
  163.     char tmppath[MAXFILELEN], line[MAXLINE], value[MAXLINE];
  164.  
  165. #ifndef AMIGA
  166.     struct passwd *pp;
  167. #endif
  168.  
  169.     FILE *fp;
  170.  
  171.     if (!strcmp(path, "NONE"))
  172.         return;
  173.     if (path[0] == '~')
  174.     {
  175.         if ((fp = fopen(path, "r")) == NULL) return;
  176.         printf("path: %s\n", path);
  177.  
  178. #ifndef AMIGA
  179.         pp = getpwuid(getuid());
  180.         sprintf(tmppath, "%s%s", pp->pw_dir, path + 1);
  181.         if ((fp = fopen(tmppath, "r")) == NULL)
  182.             return;
  183. #endif
  184.     }
  185.     else
  186.     {
  187.         if ((fp = fopen(path, "r")) == NULL) return;
  188.         printf("path: %s\n", path);
  189.     }
  190.     while (fgets(line, MAXLINE, fp) != NULL) {
  191.         if (line[0] == '#' || line[0] == '\n')
  192.             continue;
  193.         if (getconfvalue(line, "hm_mbox", value) != NULL)
  194.             strcpy(mbox, value);
  195.         if (getconfvalue(line, "hm_label", value) != NULL)
  196.             strcpy(label, value);
  197.         if (getconfvalue(line, "hm_archives", value) != NULL)
  198.             strcpy(archives, value);
  199.         if (getconfvalue(line, "hm_about", value) != NULL)
  200.             strcpy(about, value);
  201.         if (getconfvalue(line, "hm_dir", value) != NULL)
  202.             strcpy(dir, value);
  203.         if (getconfvalue(line, "hm_defaultindex", value) != NULL)
  204.             strcpy(defaultindex, value);
  205.  
  206.         if (getconfvalue(line, "hm_progress", value) != NULL)
  207.             showprogress = atoi(value);
  208.         if (getconfvalue(line, "hm_overwrite", value) != NULL)
  209.             *overwrite = atoi(value);
  210.         if (getconfvalue(line, "hm_increment", value) != NULL)
  211.             *increment = atoi(value);
  212.         if (getconfvalue(line, "hm_reverse", value) != NULL)
  213.             reverse = atoi(value);
  214.         if (getconfvalue(line, "hm_showheaders", value) != NULL)
  215.             showheaders = atoi(value);
  216.         if (getconfvalue(line, "hm_showhtml", value) != NULL)
  217.             showhtml = atoi(value);
  218.         if (getconfvalue(line, "hm_thrdlevels", value) != NULL)
  219.             thrdlevels = atoi(value);
  220.         if (getconfvalue(line, "hm_dirmode", value) != NULL)
  221.             dirmode = strtol(value, (char **) NULL, 0);
  222.         if (getconfvalue(line, "hm_filemode", value) != NULL)
  223.             filemode = strtol(value, (char **) NULL, 0);
  224.     }
  225.     fclose(fp);
  226. }
  227.